﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
  public class HighSchool
    {
      public int Id { get; set; }
        public int ProvinceId { get; set; }
        public int ZoneId { get; set; }
        public string HighSchoolDisplay { get; set; }
        public string HighSchoolName { get; set; }
        public string HighSchoolAddress { get; set; }
       private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public HighSchool()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }
     public int Insert(HighSchool obj) 
    { 
        int result = 0;
        string sql = string.Format("INSERT INTO HighSchool(ProvinceId,ZoneId,HighSchoolDisplay,HighSchoolName,HighSchoolAddress) values( '{0}', '{1}', N'{2}', N'{3}', N'{4}')" 
            , obj.ProvinceId, obj.ZoneId, obj.HighSchoolDisplay, obj.HighSchoolName, obj.HighSchoolAddress); 
        try 
        {

            result = dataConfig.ExecuteNoneQuery(sql); 
        } 
        catch (SqlException ex) 
        {
            MessageBox.Show(ex.ToString());
        } 
        return result; 
    }
       
        public int Update(HighSchool obj) 
    { 
        int result = 0;
        string sql = string.Format("UPDATE HighSchool SET ProvinceId='{0}',ZoneId= '{1}', HighSchoolDisplay=N'{2}', HighSchoolName=N'{3}',HighSchoolAddress= N'{4}' WHERE ID= N'{5}'" 
            ,  obj.ProvinceId, obj.ZoneId, obj.HighSchoolDisplay, obj.HighSchoolName, obj.HighSchoolAddress,obj.Id); 
        try 
        {

            result = dataConfig.ExecuteNoneQuery(sql); 
        } 
        catch (SqlException ex) 
        {
            MessageBox.Show(ex.ToString());
        } 
        return result; 
    }
        public int Delete(HighSchool obj)
        {
            int result = 0;
            string sql = string.Format("DELETE HighSchool Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}
